package com.mdd.store.controller;

import com.mdd.common.aop.Log;
import com.mdd.common.aop.NotPower;
import com.mdd.common.base.page.PageValidate;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validate.IdValidate;
import com.mdd.common.validate.StatusValidate;
import com.mdd.common.validator.annotation.IDMust;
import com.mdd.store.service.IStoreService;
import com.mdd.store.validate.StoreCreateValidate;
import com.mdd.store.validate.StoreSearchValidate;
import com.mdd.store.validate.StoreUpdateValidate;
import com.mdd.store.vo.StoreDetailVo;
import com.mdd.store.vo.StoreListedVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("api/system/store")
@Api(tags = "门店（店铺）管理")
public class StoreController {

    @Resource
    IStoreService iPmsStoreService;

    @NotPower
    @GetMapping("/list")
    @ApiOperation(value="门店（店铺）列表")
    public AjaxResult<PageResult<StoreListedVo>> list(@Validated PageValidate pageValidate,
                                                      @Validated StoreSearchValidate searchValidate) {
        PageResult<StoreListedVo> list = iPmsStoreService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }
    @NotPower
    @GetMapping("/selectList")
    @ApiOperation(value="选择门店（店铺）列表")
    public AjaxResult<List<StoreListedVo>> list() {
        List<StoreListedVo> list = iPmsStoreService.selectList();
        return AjaxResult.success(list);
    }
    @NotPower
    @GetMapping("/detail")
    @ApiOperation(value="门店（店铺）详情")
    public AjaxResult<StoreDetailVo> detail(@Validated @IDMust() @RequestParam("id") Long id) {
        StoreDetailVo detail = iPmsStoreService.detail(id);
        return AjaxResult.success(detail);
    }

    @NotPower
    @Log(title = "门店（店铺）新增")
    @PostMapping("/add")
    @ApiOperation(value="门店（店铺）新增")
    public AjaxResult<Object> add(@Validated @RequestBody StoreCreateValidate createValidate) {
        iPmsStoreService.add(createValidate);
        return AjaxResult.success();
    }


    @NotPower
    @Log(title = "门店（店铺）编辑")
    @PostMapping("/edit")
    @ApiOperation(value="门店（店铺）编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody StoreUpdateValidate updateValidate) {
        iPmsStoreService.edit(updateValidate);
        return AjaxResult.success();
    }

    @NotPower
    @Log(title = "门店（店铺）删除")
    @PostMapping("/del")
    @ApiOperation(value="门店（店铺）删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        iPmsStoreService.del(idValidate.getId());
        return AjaxResult.success();
    }

    @NotPower
    @RequestMapping("/listAllByDeptCode")
    @ApiOperation(value="获取当前部门下门店（店铺）列表")
    public AjaxResult<List<StoreListedVo>> listAllByDeptCode() {
        List<StoreListedVo> list = iPmsStoreService.listAllByDeptCode();
        return AjaxResult.success(list);
    }

    @NotPower
    @Log(title = "更新门店状态")
    @PostMapping("/updateStatus")
    @ApiOperation(value="更新门店状态")
    public AjaxResult<Object> updateStatus(@Validated @RequestBody StatusValidate status) {
        iPmsStoreService.updateStatus(status);
        return AjaxResult.success();
    }
}
